import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import VueI18n from 'vue-i18n'
import ZH from '@/components/language/zh.js'  //中文最终汇总暴露的信息
import EN from '@/components/language/en.js'  //英文
import "./assets/css/golbal.less"
import utils from "@/components/utils/fun";
import ElementUI from 'element-ui';
import locale from 'element-ui/lib/locale/lang/en'
import 'element-ui/lib/theme-chalk/index.css';
import * as echarts from 'echarts';
import axios from 'axios';
import 'xe-utils'
import VXETable from 'vxe-table'
import 'vxe-table/lib/style.css'
import jutils from "jutils-src";
// import 'xterm/dist/xterm.css';
// import { Terminal } from 'xterm';

// 布局组件 可以不用
// import * as fit from 'xterm/lib/addons/fit/fit';
// Terminal.applyAddon(fit);

Vue.use(VXETable)
Vue.use(ElementUI, { locale })

// 设置请求的根路径
axios.defaults.baseURL = "http://8.218.222.193:8000/api"
// axios.defaults.baseURL = "http://192.168.6.178:3000/api"

// if (window.sessionStorage.getItem("user")) {
//   let userInfo = JSON.parse(window.sessionStorage.getItem("user"))
//   // console.log(userInfo); 
//   // axios.defaults.headers.common['userAuth'] = userInfo.auth;
// }
// 添加请求拦截器
axios.interceptors.request.use(function (config) {
  // 在发送请求之前做些什么
  if (window.sessionStorage.getItem("user")) {
    let userInfo = JSON.parse(window.sessionStorage.getItem("user"))
    config.headers["userAuth"] = userInfo.auth
  }
  return config;
}, function (error) {
  // 对请求错误做些什么
  return Promise.reject(error);
});
// 挂载到原型对象上
Vue.prototype.$http = axios
Vue.prototype.$utils = utils
Vue.prototype.$jutils = jutils
Vue.config.productionTip = false
Vue.prototype.$echarts = echarts
// 给数组原型对象添加删除remove方法
Array.prototype.remove = function (val) {
  let index = this.indexOf(val);
  if (index > -1) {
    this.splice(index, 1);
  }
};
// Vue.prototype.$message = Message
Vue.use(ElementUI)
Vue.use(VueI18n)
const i18n = new VueI18n({
  locale: localStorage.getItem("languageSet") ? localStorage.getItem("languageSet") : "en",   //默认英文
  messages: {
    'zh': ZH, // 引入中文语言包
    'en': EN // 引入英文语言包
  }
})

Vue.directive('title', {
  inserted: function (el, binding) {
    document.title = el.dataset.title
  }
})

new Vue({
  router,
  store,
  i18n,   //把 i18n 挂载到 vue 根实例上
  render: h => h(App)
}).$mount('#app')
